import { _decorator, Component, Label, Node, UI } from 'cc';
import { Ally, AllyOperateType } from '../entity/Ally';
import { UIManager } from '../common/UIManager';
import AllyApi from '../api/AllyApi';
import { EventManager } from '../event/EventManager';
import { PrefabEnum } from '../common/PrefabEnum';
const { ccclass, property } = _decorator;

@ccclass('InviteOtherItem')
export class InviteOtherItem extends Component {
    @property(Label)
    title: Label
    @property(Label)
    allyName: Label
    @property(Label)
    leader: Label
  
    @property(Node)
    cancel: Node

  

    private ally: Ally

    start() {
        this.cancel.on(Node.EventType.TOUCH_END, this.onCancel, this)
       
       
    }

    setData(ally: Ally) {
        this.ally = ally
        this.title.string = `我邀请${ally.UserName}加入联盟`
        this.allyName.string = ally.AllyCutName + '的联盟'
        this.leader.string = ally.AllyCutName
    }

    async onCancel() {

        try {
            await UIManager.instance.modal('提示', `您确定撤回对${this.ally.UserName}的邀请吗？`,)
            await UIManager.instance.showLoading()
            let res = await AllyApi.Execute({
                op: AllyOperateType.CancelInvite,
                d: this.ally.InviteId
            })
            UIManager.instance.closeLoading()

            EventManager.instance.emit(EventManager.EventType.RefreshInviteOtherList, 1)
        } catch (error) {

        }
    } 
}


